<?php
require('fpdf.php');

class PDF extends FPDF
{
    function Header()
    {
        $this->Image('pics\logo.jpg',10,5,15,15);
        $this->SetFont('Arial','B',16);
        $this->SetTextColor(00,180,00);
        $this->Cell(50);
        $this->Cell(50,10,'Automated Employee Management System',0,1,'C');
        $this->Line(10,25,200,25);

    }

    function LoadData($file)
    {
        $lines = file($file);
        $data = array();
        foreach($lines as $line)
            $data[] = explode(';',trim($line));
        return $data;
    } 
    
    function SetProfileHeader($data)//Setup Attendance Report (DATE), Attendance Picture and Employee First Name
    {
        $this->Cell(20,20,'Employee Record');
        $this->SetXY(20,28);
        $this->Image('pics\record.jpg',10,33.7,10,10);
        $this->SetFont('Arial','B',12);
        $this->Cell(10, 20, $data['first']."'s". ' Profile'); 
    }
    
    function SetProfilePicture($data)//Setup Employee Picture, Employee Name and Employee Position
    {
        $this->SetXY(57,38);
        $this->Image('pics\unknown.jpg',20,45,30,30);
        $this->SetTextColor(0,0,55);
        $this->SetFont('Arial','B',16);
        $this->Cell(20, 20, $data['first'].' '.$data['middle'].' '.$data['last']);
        $this->SetXY(57,43);
        $this->SetFont('Arial','B',11);
        $this->SetTextColor(44,44,44);
        $this->Cell(20, 20, $data['position']);
    }
        
    function PrintPersonalInfo($personalHeader,$file)
    {
        $this->SetTextColor(0,0,55);
        $this->SetFont('Arial','B',12);
        $this->SetXY(10,80);
        $this->Cell(0,0,'Personal Info',0,0,'L');     
        $this->SetDrawColor(88,88,88);
        $this->Line(39,80,200,80); 
        $yHeader=1;
        foreach($personalHeader as $col)
        {
            $this->SetXY(30,85+$yHeader);
            $this->SetFont('Arial','B',11);
            $this->SetTextColor(88,88,88);
            $this->Cell(38,7,$col,0,0,'L');
            $this->Ln();
            $yHeader+=7;
        }
        foreach($file as $row)
        {
            $this->SetFont('Arial','',11);
            $this->SetTextColor(0,0,55);
            foreach($row as $col)
            {
                if($i<9)
                {
                    $this->SetXY(71,86+$yData);
                    $this->Cell(38,7,$col,0,0,'L');
                    $this->Ln();
                    $yData+=7;
                    $i++;
                }
                else if($i<13)
                {
                    $this->SetXY(71,98+$yData); 
                    $this->Cell(38,7,$col,0,0,'L');
                    $this->Ln();
                    $yData+=7;
                    $i++;
                } 
                else
                {
                    $this->SetXY(71,110+$yData); 
                    $this->Cell(38,7,$col,0,0,'L');
                    $this->Ln();
                    $yData+=7;
                    $i++; 
                }
            }       
        }
    } 
    
    function PrintEducBackground($educHeader)
    {
        $this->SetTextColor(0,0,55);
        $this->SetFont('Arial','B',12);
        $this->SetXY(10,155);
        $this->Cell(0,0,'Educational Background',0,0,'L');     
        $this->SetDrawColor(88,88,88);
        $this->Line(62,155,200,155); 
        $yHeader=1;
        foreach($educHeader as $col)
        {
            $this->SetXY(30,160+$yHeader);
            $this->SetFont('Arial','B',11);
            $this->SetTextColor(88,88,88);
            $this->Cell(38,7,$col,0,0,'L');
            $this->Ln();
            $yHeader+=7;
        }
    } 
    
    function PrintEmergencyContact($contactHeader)
    {
        $this->SetTextColor(0,0,55);
        $this->SetFont('Arial','B',12);
        $this->SetXY(10,195);
        $this->Cell(0,0,'Emergency Contact',0,0,'L');     
        $this->SetDrawColor(88,88,88);
        $this->Line(52,195,200,195); 
        $yHeader=1;
        foreach($contactHeader as $col)
        {
            $this->SetXY(30,200+$yHeader);
            $this->SetFont('Arial','B',11);
            $this->SetTextColor(88,88,88);
            $this->Cell(38,7,$col,0,0,'L');
            $this->Ln();
            $yHeader+=7;
        }
        $this->Line(10, 225, 200, 225);
    } 
}

/*Declare Variables Here*/
$profheader = array(
    'first'=>'Tonny',
    'middle'=>'Salcedo',
    'last'=>'Quintos',
    'position'=>'System Admin');

$personalHeader = array('First Name','Middle Name','Last Name','Address','Birthdate','Gender','Position','Contact Number','Email');
$educHeader = array('High School','      School Year','College','      Academic Year');
$contactHeader = array('Primary','      Address','      Contact');



/*End of Declaration*/

/*Main*/
$pdf = new PDF();
$pdf->AddPage();
$file = $pdf->LoadData('bla.txt');
$pdf->SetProfileHeader($profheader);
$pdf->SetProfilePicture($profheader);

$pdf->PrintPersonalInfo($personalHeader,$file);
$pdf->PrintEducBackground($educHeader);
$pdf->PrintEmergencyContact($contactHeader);
$pdf->Output();
/*End of Main*/
?>
